﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using com.cgWorkstudio.BIMP.Library.Properties;
using com.cgWorkstudio.BIMP.Library.vo;

namespace com.cgWorkstudio.BIMP.Library.uc {
    /// <summary>
    /// LeftButton
    /// </summary>
    public partial class UC_LeftButton:UserControl {
        //CGLeftButtonType _buttonType = CGLeftButtonType.岗位管理;
        //[Description("按钮类型")]
        //public CGLeftButtonType LeftButtonType {
        //    get {
        //        return _buttonType;
        //    }
        //    set {
        //        _buttonType = value;
        //        //setDefaultPic(true);
        //    }
        //}
        /// <summary>
        /// 
        /// </summary>
        public UC_LeftButton() {
            InitializeComponent();
            BindMouseAction();
            //this.showButtonPic.MouseMove += new MouseEventHandler(UC_LeftButton_MouseMove);
            //this.showButtonPic.MouseLeave += new EventHandler(UC_LeftButton_MouseLeave);
            //this.showButtonPic.MouseDown += new MouseEventHandler(showButtonPic_MouseDown);
            //this.showButtonPic.MouseUp += new MouseEventHandler(showButtonPic_MouseUp);
        }

        private void BindMouseAction() {
            this.showButtonText.MouseMove += new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonText.MouseLeave += new EventHandler(showButtonText_MouseLeave);
            this.showButtonText.MouseDown += new MouseEventHandler(showButtonText_MouseDown);
            this.showButtonText.MouseUp += new MouseEventHandler(showButtonText_MouseUp);

            this.showButtonPic.MouseMove += new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonPic.MouseMove += new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonPic.MouseLeave += new EventHandler(showButtonText_MouseLeave);
            this.showButtonPic.MouseDown += new MouseEventHandler(showButtonText_MouseDown);
        }
        void UnBindMouseAction() {
            this.showButtonText.MouseMove -= new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonText.MouseLeave -= new EventHandler(showButtonText_MouseLeave);
            this.showButtonText.MouseDown -= new MouseEventHandler(showButtonText_MouseDown);
            this.showButtonText.MouseUp -= new MouseEventHandler(showButtonText_MouseUp);

            this.showButtonPic.MouseMove -= new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonPic.MouseMove -= new MouseEventHandler(showButtonText_MouseMove);
            this.showButtonPic.MouseLeave -= new EventHandler(showButtonText_MouseLeave);
            this.showButtonPic.MouseDown -= new MouseEventHandler(showButtonText_MouseDown);
        }

        bool buttonChecked = false;
        /// <summary>
        /// 选择按钮
        /// </summary>
        public void selectButton() {
            buttonChecked = true;
            mouseMoving = true;
            //showButtonText_MouseDown(null,null);
            this.BackgroundImage = Resources.Png_LeftButton_Checked;
            this.showButtonText.Padding = new Padding(0,1,0,0);
            this.showButtonPic.Top = 1;   
        }
        /// <summary>
        /// 默认状态
        /// </summary>
        public void unSelectButton() {
            buttonChecked = false;
            showButtonText_MouseLeave(null,null);
            this.showButtonPic.Top = 0;
        }

        public delegate void OnLeftButtonClickedCallBack(UC_LeftButton leftButton);
        public event OnLeftButtonClickedCallBack OnLeftButtonClicked;
        bool mouseMoving = false;
        void showButtonText_MouseUp(object sender,MouseEventArgs e) {
            if(buttonChecked == true) {
                return;
            }
            mouseMoving = true;
            this.BackgroundImage = Resources.Png_LeftButton_Actived;
            this.showButtonText.Padding = new Padding(0);
            OnLeftButtonClicked(this);
            if(buttonChecked == false) {
                this.showButtonPic.Top = 0;
            }
        }

        void showButtonText_MouseDown(object sender,MouseEventArgs e) {
            if(buttonChecked == true) {
                return;
            }
            mouseMoving = true;
            this.BackgroundImage = Resources.Png_LeftButton_Down;
            this.showButtonText.Padding = new Padding(0,1,0,0);
            this.showButtonPic.Top = 1;           
        }

        void showButtonText_MouseLeave(object sender,EventArgs e) {
            if(buttonChecked == true) {
                return;
            }
            mouseMoving = false;
            this.BackgroundImage = Resources.Png_LeftButton_Default;
            this.showButtonText.Padding = new Padding(0);
        }

        void showButtonText_MouseMove(object sender,MouseEventArgs e) {
            if(buttonChecked == true) {
                return;
            }
            if(mouseMoving == true) {
                return;
            }
            mouseMoving = true;
            this.BackgroundImage = Resources.Png_LeftButton_Actived;
            this.showButtonText.Padding = new Padding(0);
        }
        /// <summary>
        /// 按钮文本
        /// </summary>
        [Description("按钮文本")]
        public string CGButtonText {
            get {
                return showButtonText.Text;
            }
            set {
                showButtonText.Text = value;
            }
        }
        /// <summary>
        /// 按钮图片
        /// </summary>
        [Description("按钮图片")]
        public Image CGButtonImage {
            get {
                return showButtonPic.BackgroundImage;                
            }
            set {
                showButtonPic.BackgroundImage = value;
            }
        }
        [Description("文本大小")]
        public float CGFontSize {
            get {
                return showButtonText.Font.Size;
            }
            set {
                showButtonText.Font = new Font(new FontFamily("华文细黑"),value);
            }
        }
        //void showButtonPic_MouseUp(object sender,MouseEventArgs e) {
        //    mouseMoving = true;
        //    setDefaultPic(false);
        //}

        //private void setDefaultPic(bool showDefault) {
        //    if(showDefault == true) {
        //        this.BackgroundImage = null;
        //    }
        //    switch(LeftButtonType) {
        //        case CGLeftButtonType.岗位管理:
        //            this.showButtonPic.Image = Resources.Png_岗位管理_Default;
        //            break;
        //        case CGLeftButtonType.工资结算:
        //            this.showButtonPic.Image = Resources.Png_工资结算_Default;
        //            break;
        //        case CGLeftButtonType.顾问组别:
        //            this.showButtonPic.Image = Resources.Png_顾问组别_Default;
        //            break;
        //        case CGLeftButtonType.轮牌分类:
        //            this.showButtonPic.Image = Resources.Png_轮牌分类_Default;
        //            break;
        //        case CGLeftButtonType.员工考勤:
        //            this.showButtonPic.Image = Resources.Png_员工考勤_Default;
        //            break;
        //        case CGLeftButtonType.员工排班:
        //            this.showButtonPic.Image = Resources.Png_员工排班_Default;
        //            break;
        //        case CGLeftButtonType.员工信息:
        //            this.showButtonPic.Image = Resources.Png_员工信息_Default;
        //            break;
        //    }            
        //}

        //void showButtonPic_MouseDown(object sender,MouseEventArgs e) {
        //    mouseMoving = true;
        //    setActivedPic();
        //}

        //void setActivedPic() {
        //    switch(LeftButtonType) {
        //        case CGLeftButtonType.岗位管理:
        //            this.showButtonPic.Image = Resources.Png_岗位管理_Down;
        //            break;
        //        case CGLeftButtonType.工资结算:
        //            this.showButtonPic.Image = Resources.Png_工资结算_Down;
        //            break;
        //        case CGLeftButtonType.顾问组别:
        //            this.showButtonPic.Image = Resources.Png_顾问组别_Down;
        //            break;
        //        case CGLeftButtonType.轮牌分类:
        //            this.showButtonPic.Image = Resources.Png_轮牌分类_Down;
        //            break;
        //        case CGLeftButtonType.员工考勤:
        //            this.showButtonPic.Image = Resources.Png_员工考勤_Down;
        //            break;
        //        case CGLeftButtonType.员工排班:
        //            this.showButtonPic.Image = Resources.Png_员工排班_Down;
        //            break;
        //        case CGLeftButtonType.员工信息:
        //            this.showButtonPic.Image = Resources.Png_员工信息_Down;
        //            break;
        //    } 
        //}

        //bool mouseMoving = false;
        //void UC_LeftButton_MouseLeave(object sender,EventArgs e) {
        //    //mouseMoving = false;
        //    //setDefaultPic(true);
        //}

        //void UC_LeftButton_MouseMove(object sender,MouseEventArgs e) {
        //    if(mouseMoving == true) {
        //        return;
        //    }
        //    mouseMoving = true;
        //    //this.BackgroundImage = Resources.Png_LeftButton_Actived;                        
        //}
    }
}
